def sum(n):
    result = 0
    for i in xrange(n):
        result += i
    return result

